import React from "react";
import Admin from "../../../layout/Admin";
import MatchModel from "../../../model/Match";
import {Table,} from 'antd'
import PaginationFooter from "../../../component/PaginationFooter/PaginationFooter";
import moment from "moment";

class LiveList extends React.Component {
    constructor(props) {
        super(props)
        this.model = new MatchModel()
        this.columns = [

            {
                title: '比赛',
                render: (_, record) => `${record.Name[0]} ${record.Kename[0]} ${record.Zhuname[0]}`,
            },

            {
                title: '操作',
                render: (_, record) => {
                    return <div>
                        <a
                            onClick={() => this.switchLiveStatus(record)}
                            style={{marginRight: '8px',}}
                        >{record.Isshow === 0 ? '关闭直播' : '开启直播'}</a>
                    </div>
                }
            }
        ]

        this.state = {
            list: [],
            p: 0,
        }
    }

    componentDidMount() {
        this.live()
    }

    live() {
        this.model
            .live()
            .then((resp) => {
                const list = resp.data.ok
                if (list) {
                    this.setState({
                        list,
                    })
                }
            })
    }

    switchLiveStatus(game) {
        // Namiid int `binding:"required"`
        // Source int //1=关，0=开
        this.model
            .switchLive({Namiid: game.Id, Source: game.Isshow === 0 ? 1 : 0,})
            .then(resp => {
                if (resp.data.ok) {
                    this.live()
                }
            })

    }

    render() {
        return <Admin>
            <div className='list-container'>
                <Table
                    rowKey={(record, index) => index}
                    dataSource={this.state.list}
                    columns={this.columns}
                    // pagination={false}
                />
                {/*<PaginationFooter*/}
                {/*    prevPage={() => this.prevPage()}*/}
                {/*    nextPage={() => this.nextPage()}*/}
                {/*/>*/}
            </div>
        </Admin>
    }
}

export default LiveList